<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <title>评审管理(二等奖二次评审)</title>
    <link rel="stylesheet" href="/static/plugin/layui/css/layui.css" media="all" />
    <script src="/static/plugin/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/static/plugin/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/base.js"></script>
    <script type="text/javascript" src="/static/js/formSelects.js"></script>
    <script type="text/javascript" src="/static/js/highcharts.js"></script>
    <script type="text/javascript" src="/static/js/jquery.media.js"></script>
    <script type="text/javascript" src="/static/js/base64.min.js"></script>
<body class="layui-anim">
<div class="x-body">
    &nbsp;
    <div class="layui-row" style="margin-bottom: 18px;">
        <div class="layui-form">
            <div class="layui-input-inline">
                <div class="layui-input-inline" style="width: 150px">
                    <input class="layui-input" id="keyword01" placeholder="请输入名称" style="width: 150px">
                </div>
                <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
                <button class="layui-btn" id="appraise"><i class="layui-icon layui-icon-duigou"></i>确认评审</button>



                <div style="display: none" id="aminId">
                    <button class="layui-btn" id="updateAppraise"><i class="layui-icon layui-icon-duigou"></i>调整推荐个数</button>
                </div>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <span id="adminId2" style="color: red;display: none">您可以评选二等奖：<span th:text="${company}"></span>&nbsp;项</span>
            </div>
        </div>
    </div>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
</div>
<!--评审框-->
<div id="appraiseDiv" style="display:none">
    <form class="layui-form" id="appraiseFormID" style="margin-top:20px">
        <input hidden id="id" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-inline" style = "width:300px;">
                <input type="text" id="pname" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                判定等级<span style="color: red">*</span>
            </label>
            <div class="layui-input-inline" style = "width:300px;">
                <select lay-verify="cid" id="level" name="level" lay-search="">
                    <option value="1">一等奖A</option>
                    <option value="2">一等奖B</option>
                    <option value="3">一等奖C</option>
                    <option value="4">二等奖A</option>
                    <!--<option>二等奖B</option>
                    <option>二等奖C</option>-->
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">评审人</label>
            <div class="layui-input-inline" style = "width:300px;">
                <input type="text" th:value="${session.user.username}" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 70px">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-blue" lay-submit lay-filter="appraiseform" id="appraiseSubform">提交</button>
                <button class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
</div>


<div id="appraiseDiv2" style="display:none">
    <form class="layui-form" id="appraiseFormID2" style="margin-top:20px">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">同意数量调整</label>
            <div class="layui-input-inline" style = "width:300px;">
                <input type="text" id="pname2"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="margin-left: 70px">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-blue" lay-submit lay-filter="appraiseSubform2" id="appraiseSubform2">提交</button>
                <button class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
</div>


<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="introduction" style="font-size: 16px">项目简介</a>
</script>
<script type="text/html" id="jystate">

    {{# if(d.state == 1){}}
    <div style="background-color: #00BB00;">已评审</div>
    {{# } else { }}
    <div style="background-color: #FF0000;">待评审</div>
    {{# } }}

</script>
<script th:inline="javascript">
    let idea = [[${idea}]];
    let userId = [[${userId}]]
    let company = [[${company}]]

    if (typeof(company) === 'undefined' || company == null || company === '') {

    }else {
        var dropBox = document.getElementById("adminId2");
        dropBox.style.display = "inline";
    }

    var dropBox = document.getElementById("aminId");
    setTimeout(function () {
        if (userId == 35) {
            dropBox.style.display = "inline";
        }
    },600)

    layui.config({
        base: '/static/module/'
    }).extend({
        tableEdit:'js/tableEdit'
    }).use(['table','layer','upload','form','laydate','element','tableEdit'], function(){
        var table = layui.table;
        var form=layui.form;
        var tableEdit = layui.tableEdit;

        var $ = layui.jquery, active = {
            reload:function () {
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'realName':$('#keyword01').val()
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }

        var params = [
            {name:'1', value: '一等奖'},
            {name:'4', value: '二等奖'},
            {name:'7', value: '三等奖'}
        ];

        var cols = table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/appraise2/selectProjectByUser?idea='+idea
            ,height: 'full-90'
            ,limit:40
            ,cols: [
                [ //表头
                    {field: 'id',type: 'checkbox', align:'center', fixed: 'left'}
                    /*,{field:'uid', title:'序号', width: 55, type:'numbers',align:'center'}*/
                    ,{field: 'pnumber', title: '项目序号', align:'center',width: 100,
                        templet: function(d) {
                            return d.project.pnumber;
                        }
                    }
                    ,{field: 'pname', title: '名称',
                        templet: function(d) {
                            return d.project.pname;
                        }
                    }
                    ,{field: 'type', title: '类型', align:'center',width: 210,
                        templet: function(d) {
                            return d.project.type;
                        }
                    }
                    /*,{field: 'idea', title: '专业组评审意见', align:'center',width: 150,
                        templet: function(d) {
                            let idea = d.project.idea;
                            if (typeof idea != null &&  typeof idea != 'undefined') {
                                return idea;
                            }
                            return "";
                        }
                    }*/
                   /*, {field:'level',align:'center', title: '我的评审▽',width: 120
                        ,event:'danxuan',config:{type:'select',data:params}
                        ,templet:function (d) {

                            if(d.level){
                                if(d.level.value){
                                    return  d.level.value;
                                }else if (d.level == 1){
                                    return '一等奖';
                                }else if (d.level == 4){
                                    return '二等奖';
                                }else if (d.level == 7){
                                    return '三等奖';
                                }
                                return  d.level;
                            }
                            return '请选择'
                        }
                    }*/
                    ,{field: 'state1', title: '评定意见', align:'center',width: 300,templet:function (d) {
                        let id = d.id;
                        let evaluationOpinion = d.evaluationOpinion;
                        let actions = [];

                        if (evaluationOpinion == 0) {
                            actions.push('<input type="radio" name="gender'+id+'" value="0" checked/>同意')
                            actions.push('<input type="radio" name="gender'+id+'" value="1"/>不同意')
                        }else if (evaluationOpinion == 1) {
                            actions.push('<input type="radio" name="gender'+id+'" value="0"/>同意')
                            actions.push('<input type="radio" name="gender'+id+'" value="1" checked/>不同意')
                        }else if (typeof(evaluationOpinion) == 'undefined'){
                            actions.push('<input type="radio" name="gender'+id+'" value="0"/>同意')
                            actions.push('<input type="radio" name="gender'+id+'" value="1" checked/>不同意')
                        }
                        return actions.join("&nbsp;")
                    }}
                    /*,{field: 'state2', title: '打分(0-100)', align:'center',width: 140,templet:function (d) {
                        let id = d.id;
                        let scoring = d.scoring;
                        return '<input type="number" style="width: 100%" id = "numberId'+id+'" value="'+scoring+'">'
                    }}*/
                    ,{field: 'state', title: '状态', align:'center', templet: '#jystate',width: 100}
                    //,{field: 'remark', title: '操作', toolbar: "#toolBar", width: 120}
                   /* ,{field: 'remark', title: '操作',width: 300,
                    templet:function (d) {
                        let ppt = d.project.ppt;
                        let pdf = d.project.url;
                        let tempUrl;
                        let temp;
                        $.ajax({
                            type:'get',
                            url:"/project/introductionCheck?fileName="+ppt+"&type=ppt",
                            async:false,
                            success:function (result) {
                                //console.log(result);
                                temp = result;
                            }
                        });
                        $.ajax({
                            type:'get',
                            url:"/project/introductionCheck?fileName="+d.project.url+"&type=pdf",
                            async:false,
                            success:function (result) {
                                //console.log(result);
                                tempUrl = result;
                            }
                        });
                        if (temp && tempUrl) {
                            let actions = [];

                            actions.push('<a href="#" onclick="lookPdf(\''+pdf+'\')"  class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal" lay-event="introduction"  style="font-size: 16px">项目简介PDF</a>');
                            return actions.join("")
                        }else {
                            return '<a class="layui-btn layui-btn-xs  layui-btn-disabled" lay-event="introduction"  style="font-size: 16px">项目简介</a>';
                        }
                    }
                }*/
                ]
            ]
            , page: false
            ,totalRow: true
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#3388CB', 'color': '#fff','font-weight':'bold','font-size': '16px'
                })
                $('td').css({
                    'font-weight':'bold','font-size': '16px'
                })
            }
        }).config.cols;
        var aopTable = tableEdit.aopObj(cols); //获取一个aop对象
        aopTable.on('tool(tableList)',function (obj) {
            var event = obj.event; //当前单元格事件属性值

            if(event === 'danxuan'){
                if(obj.data.state == 1){
                    layer.alert("已评审的数据不能再评审！",{icon :5})
                    return;
                }
                var field = obj.field; //单元格字段
                var value = obj.value; //修改后的值
                var id = obj.data.id; //当前行旧数据
                var update = {};
                update[field] = value;
                //把value更新到行中
                obj.update(update);
                $.ajax({
                    type: 'post',
                    url: '/appraise2/appraise',
                    async: false,
                    data: {id: id, level: value.name},
                }).done(
                    function (res) {
                    }
                ).fail(
                    function () {
                        layer.msg('请联系管理员', {icon: 2})
                        setTimeout(function () {
                            location.reload();
                        }, 1000);
                    }
                )

            }else if(obj.event === 'introduction'){
                var ppt = obj.data.project.ppt;
                let temp;
                $.ajax({
                    type:'get',
                    url:"/project/introductionCheck?fileName="+ppt,
                    async:false,
                    success:function (result) {
                        //console.log(result);
                        temp = result;
                    }
                });
                if (temp) {
                    window.location.href = "/project/introduction?fileName="+ppt;
                }
            }
        });


        //监听行单击事件（点击行内下拉框事件）
        table.on('row(tableList)', function(obj){
        });
        //监听双单击事件（点击下载PDF）
        /*table.on('rowDouble(tableList)', function(obj){
            var url2 =  obj.data.project.url;

            let temp;
            $.ajax({
                type:'get',
                url:"/static/pdf/"+url2,
                async:false,
                success:function (result) {
                    //console.log("正确");
                    temp = true;
                },
                error:function (result) {
                    //console.log("错误");
                    temp = false;
                }
            });
            if (temp) {
                window.location.href = "/static/pdf/"+url2;
            }
        });*/

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        let host = window.location.host
        let hostname = window.location.hostname
        window.lookPpt=function(ppt) {
            //var ppt = obj.data.project.ppt;
            let temp;
            $.ajax({
                type:'get',
                url:"/static/ppt/"+ppt,
                async:false,
                success:function (result) {
                    //console.log(result);
                    temp = result;
                },
                error:function (result) {
                    //console.log("错误");
                    temp = false;
                }
            });
            if (temp) {
                /*var url = "http://" + host + "/static/ppt/"+ppt; //要预览文件的访问地址
                window.open("http://" + hostname+':8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url)));*/
                window.parent.location.href = "/static/ppt/"+ppt;
            }
        }

        window.lookPdf=function(pdf) {
            let temp;
            $.ajax({
                type:'get',
                url:"/static/pdf/"+pdf,
                async:false,
                success:function (result) {
                    //console.log("正确");
                    temp = true;
                },
                error:function (result) {
                    //console.log("错误");
                    temp = false;
                }
            });
            if (temp) {
                //window.location.target="_blank";
                //window.parent.location.href = "/static/pdf/"+pdf;
                window.open("/static/pdf/"+pdf, "_blank")
            }
        }



        $('#lookPdfId').click(function () {
            let temp;
            $.ajax({
                type:'get',
                url:"/static/pdf/"+url2,
                async:false,
                success:function (result) {
                    //console.log("正确");
                    temp = true;
                },
                error:function (result) {
                    //console.log("错误");
                    temp = false;
                }
            });
            if (temp) {
                window.location.href = "/static/pdf/"+url2;
            }
        });

        //结果调整
        $("#updateAppraise").click(function(){
            layer.open({
                type: 1 ,				//Page层类型
                area: ['440px', '320px'] 	//宽  高
                ,title: '推荐个数调整'
                ,shade: 0.6 			//遮罩透明度
                ,maxmin: true 			//允许全屏最小化
                ,anim: 1 				//0-6的动画形式，-1不开启
                ,content: $('#appraiseDiv2')
                ,success: function(){
                    form.render();
                }
            });
        });

        //评审
        $("#appraise").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            let submitDataList = [];
            let checkDataList = [];
            for (let i = 0; i < data.length; i++) {
                const day3Element = data[i];
                console.log(JSON.stringify(day3Element.id));
                let obj = document.getElementsByName("gender"+day3Element.id);
                //let scoring = document.getElementById(("numberId"+day3Element.id)).value;
                let scoring = 0;
                let check_val = [];
                for(k in obj){
                    if(obj[k].checked)
                        check_val.push(obj[k].value);
                }
                let va = /^([0-9]{1,2}|100)$/;
                //alert(va.test(scoring));
                //alert(check_val != '');
                if ((check_val != '') == false) {
                    layer.alert("提交的“评审意见”不符合规范！！！",{icon :5})
                    return;
                }
                let submitData = {
                    id:day3Element.id,
                    evaluationOpinion:check_val[0],
                    scoring:scoring
                }

                let checkData = {
                    id:day3Element.id,
                    evaluationOpinion:check_val[0],
                    scoring:scoring,
                    idea:idea
                }
                submitDataList.push(submitData);
                checkDataList.push(checkData);
            }

            if(data.length == 0){
                layer.alert("请勾选要操作的项！",{icon :5})
            }else {
                /*for(var i=0;i < data.length;i++){
                    if(data[i].state == 1){
                        layer.alert("已评审的数据不能再评审！",{icon :5})
                        return;
                    }
                }*/
                let index = {};
                $.ajax({
                    type: 'post',
                    url: '/appraise2/booleanSubmit',
                    async: false,
                    data:{json:JSON.stringify(checkDataList)},
                    success:function(result) {
                        console.log(result);
                        if (result.length != 0) {
                            index = result;
                        }
                    }
                });

                if (index.code == 100) {
                    layer.alert("您最多可以推荐"+index.msg+"个二等奖",{icon :5})
                    return;
                }


                layer.confirm('确定提交评审吗？提交后不可更改评审结果', {
                    btn: ['确定', '取消']
                }, function (index) {
                    layer.close(index);//关闭 layer.confirm
                    //此处请求后台程序，下方是成功后的前台处理……
                    var index = layer.load(0,{shade: [0.7, '#393D49']}, {shadeClose: true}); //0代表加载的风格，支持0-2
                    var count = 0;
                    for (var i=0;i < submitDataList.length;i++) {
                        var id = submitDataList[i].id
                        $.ajax({
                            type: 'post',
                            url: '/appraise2/submit',
                            async: false,
                            data: submitDataList[i],
                        }).done(
                            function (res) {
                                if (res == true) {
                                    count ++;
                                } else {
                                    layer.msg("请联系管理员！", {icon: 2})
                                }
                            }
                        ).fail(
                            function () {
                                layer.msg('请联系管理员', {icon: 2})
                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                            }
                        )
                        if(count > 0) {
                            layer.msg('评审成功', {icon: 1})
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                        }
                    }
                });
                /*layer.confirm('确定提交评审吗？提交后不可更改评审结果', function(index) {
                    layer.close(index);
                });*/
            }
        });

        form.on('submit(appraiseSubform2)', function () {
            $("#appraiseSubform").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'/project/updateProject',
                data:{num:$('#pname2').val(),idea:"二等奖"},
                cache:false,
            }).done(
                function(res) {
                    if (res) {
                        layer.msg('调整成功',{icon:6})
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    layer.msg('调整失败',{icon:5})
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })
    });
</script>
</body>

</html>
